<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

//////////////////////////////////////////////////
// USER CONTROLLER
//////////////////////////////////////////////////
class User extends TMT_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	/////////////////////////////////
	// INDEX FUNCTION
	//  
	/////////////////////////////////#
	
	
	function index()
	{
		$this->set_content_view('user/details');
		$this->details();
	}
	
	public function details()
	{		
		$this->headline = 'Persönliche Einstellungen';
	
		$this->load->library('table');
		$this->load->helper('form');
		
		
		$this->view_data['employee'] = $this->employee;
		$teamroles = $this->employee->teamrole();
		$this->view_data['active_teamrole'] = $teamroles[$this->active_team];
		
		//Form data
		$this->view_data['form']['target']			= '/user/change_password';
		$this->view_data['form']['pw_old']			= array(
											'type' => 'password',
											'name' => 'pw_old',
											'required' => 'required');
											
		$this->view_data['form']['pw_new']			= array(
											'type' => 'password',
											'name' => 'pw_new',
											'required' => 'required');
											
		$this->view_data['form']['pw_approve']		= array(
											'type' => 'password',
											'name' => 'pw_approve',
											'required' => 'required');
		$this->view_data['form']['submit']			= array(
											'type' => 'submit',
											'name' => 'submit',
											'value'=> 'Passwort ändern',
											'class'=> 'btn'
											);
											
		
		$this->view_data['success'] = $this->uri->segment(3) === 'success' 	? TRUE : NULL;
		$this->view_data['error'] 	= $this->uri->segment(3) === 'error' 	? TRUE : NULL;									
	}
	
	
	function change_password()
	{
		$this->load->library('form_validation');
		$this->load->library('tank_auth');
		$this->lang->load('tank_auth');
		$this->form_validation->set_rules('pw_old','Altes Passwort','trim|required|xss-clean');
		$this->form_validation->set_rules('pw_new','Neues Passwort','trim|required|matches[pw_approve]|xss-clean');
		$this->form_validation->set_rules('pw_approve','Neues Passwort','trim|required|xss-clean');
		$this->form_validation->set_rules('submit','Passwort ändern','required');
		
		$redirect_path = 'user/details/error';
		if($this->form_validation->run())
		{	
			echo 'Test';
			if ($this->tank_auth->change_password($this->form_validation->set_value('pw_old'),$this->form_validation->set_value('pw_new'))) 											//Login by E-Mail
			{
				$redirect_path = 'user/details/success';
			}
			
		}
		
		redirect($redirect_path);
	}
}


/* End of file user.php */
/* Location: ./application/controllers/user.php */